package com.wwwarehouse.usercenter.fragment.permissiondistribute;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.wwwarehouse.common.activity.BaseCardDeskActivity;
import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.bean.response.CardDeskFunctionResponseBean;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.common.eventbus_event.CardDeskEvent;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.constant.UserCenterConstant;

import de.greenrobot.event.EventBus;


/**
 * 分配权限->找不到该权限
 * Created by ShineF on 2017/9/28 0025.
 */


public class PermissionAddressNotFoundFragment extends BaseFragment {


    private Button mNotFoundBtn;
    private TextView mTvContent;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_address_permission_notfound, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        mNotFoundBtn = $(R.id.btn_select_other_distribute);
        mTvContent = $(R.id.tv_desc);
        ((BaseCardDeskActivity) mActivity).hideBackBt();
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        ((BaseCardDeskActivity) mActivity).showBackBt();
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof PermissionAddressNotFoundFragment) {
            mActivity.setTitle(R.string.receiver_permission);
        }
    }

    @Override
    public void requestDatas() {
        final String mBusinessUnitId = sp.getValue(UserCenterConstant.SAVE_BUSINESSUNITID);
        final Bundle arguments = getArguments();
        if (null == arguments) {
            return;
        }
        final String type = arguments.getString("type");
        if (null == type) {
            return;
        }
        String content = arguments.getString("content");
        if (content != null) {
            mTvContent.setText(content);
        }
        mNotFoundBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                CardDeskFunctionResponseBean.TaskBean bean = new CardDeskFunctionResponseBean.TaskBean();
                switch (type) {
                    case "distribution":
                        bean.setBusinessId(mBusinessUnitId);
                        bundle.putSerializable(Constant.KEY_CARD_DESK_FUNCTION_DETAILS, bean);
                        break;
                    case "CheckDownClassFragment":
                        bundle.putString("personName", arguments.getString("personName"));
                        bundle.putString("userId", arguments.getString("userId"));
                        bundle.putString("buId", arguments.getString("buId"));
                        bundle.putString("CheckDownClassFragment", "CheckDownClassFragment");
                        break;
                }
                AuthorityDistributePagerFragment fragment = new AuthorityDistributePagerFragment();
                fragment.setArguments(bundle);
                EventBus.getDefault().post(new CardDeskEvent("clear_back_stack"));
                pushFragment(fragment);
            }
        });
    }
}
